<div class="row">
	<div class="col-xs-12 col-md-12">
		<div class="widget">
			<div class="widget-header bg-blue">
				<i class="widget-icon fa fa-arrow-down"></i>
				<span class="widget-caption">卡券列表</span>
				<div class="widget-buttons">
					<a href="#" data-toggle="maximize">
						<i class="fa fa-expand"></i>
					</a>
					<a href="#" data-toggle="collapse">
						<i class="fa fa-minus"></i>
					</a>
					<a href="#" data-toggle="dispose">
						<i class="fa fa-times"></i>
					</a>
				</div>
			</div>
			<div class="widget-body">
				<div class="table-toolbar">
					<a href="{:U('Cms/Vip/cardSet/')}" class="btn btn-primary" data-loader="Joel-loader" data-loadername="卡券设置">
						<i class="fa fa-plus"></i>新增卡券
					</a>
					<a href="#" class="btn btn-danger" id="Joel-delall">
						<i class="fa fa-times"></i>删除卡券
					</a>
					<eq name="type" value="2">
					<a href="#" class="btn btn-success" id="sendCard">
						<i class="fa fa-delicious"></i>发送卡券
					</a>
					</eq>
					<div class="pull-right">
						<form id="Joel-search">
							<label style="margin-bottom: 0px;">
								<input name="search" type="search" class="form-control input-sm" placeholder="卡券编号">
							</label>
							<a href="{:U('Cms/Vip/card',array('type'=>$type))}" class="btn btn-success" data-loader="Joel-loader" data-loadername="卡券列表" data-search="Joel-search">
								<i class="fa fa-search"></i>搜索
							</a>
							&nbsp;&nbsp;
							<button href="javascript:void(0)" class="btn btn-primary" id="exportCard"><i class="fa fa-save"></i>导出卡券</button>
						</form>
						
					</div>
				</div>

				<table id="Joel-table" class="table table-bordered table-hover">
					<thead class="bordered-darkorange">
						<tr role="row">
							<th width="20px"><div class="checkbox" style="margin-bottom: 0px; margin-top: 0px;">
									<label style="padding-left: 4px;"> <input type="checkbox" class="Joel-checkall colored-blue">
                                     <span class="text"></span>
									</label>                                    
                                </div></th>
							<th width="50px">ID</th>
							<th width="100px">类型</th>
							<th width="150px">卡券编号</th>
							<in name="pwd" value="$useroath">
								<th width="100px">卡密</th>
							</in>	
							<th width="100px">金额</th>
							<th width="200px">有效期</th>
							<th width="150px">使用规则</th>
							<th width="100px">创建时间</th>
							<th width="100px">状态</th>
							<th width="100px">所属会员ID</th>
							<th width="100px">使用时间</th>
							<th width="300px">操作</th>
						</tr>
					</thead>
					<tbody>
						<volist name="cache" id="vo">
							<tr id="item{$vo.id}">
								<td>
									<div class="checkbox" style="margin-bottom: 0px; margin-top: 0px;">
										<label style="padding-left: 4px;"> <input name="checkvalue" type="checkbox" class="colored-blue Joel-check" value="{$vo.id}">
	                                     <span class="text"></span>
										</label>                                    
	                                </div>
								</td>
								<td class=" sorting_1">{$vo.id}</td>
								<td class=" " id="type{$vo.id}"><eq name="vo.type" value="1">充值卡</eq><eq name="vo.type" value="2">代金券</eq></td>
								<td class=" ">{$vo.cardno}</td>
								<in name="pwd" value="$useroath">
									<td class=" ">{$vo.cardpwd}</td>
								</in>
								<td class=" " id="money{$vo.id}">{$vo.money}</td>
								<td class=" "><if condition="$vo.stime neq 0">{$vo.stime|date='Y-m-d',###}至{$vo.etime|date='Y-m-d',###}</if></td>
								<td class=" "><if condition="$vo.usemoney neq 0">满{$vo.usemoney}元使用</if></td>
								<td class=" ">{$vo.ctime|date='Y-m-d',###}</td>
								<td class=" " id="status{$vo.id}"><eq name="vo.status" value="0">生成</eq><eq name="vo.status" value="1">已发卡</eq><eq name="vo.status" value="2">已使用</eq></td>
								<td class=" "><if condition="$vo.vipid neq 0">{$vo.vipid}</if></td>
								<td class=" "><eq name="vo.status" value="2">{$vo.usetime|date='Y-m-d',###}</eq></td>
								<td class="center "><a href="{:U('Cms/vip/card/')}" class="btn btn-danger btn-xs" data-type = "del" data-ajax="{:U('Cms/vip/cardDel/',array('id'=>$vo['id']))}" ><i class="fa fa-trash-o"></i> 删除</a></eq></td>
							</tr>
						</volist>
												
					</tbody>
				</table>
				<div class="row DTTTFooter">
					{$page}
				</div>
			</div>
		</div>
	</div>
</div>
<!--面包屑导航封装-->
<div id="tmpbread" style="display: none;">{$breadhtml}</div>
<script type="text/javascript">
	setBread($('#tmpbread').html());
</script>
<!--/面包屑导航封装-->
<!--全选特效封装/全部删除-->
<script type="text/javascript">
	//全选
	var checkall=$('#Joel-table .Joel-checkall');
	var checks=$('#Joel-table .Joel-check');
	var trs=$('#Joel-table tbody tr');
	$(checkall).on('click',function(){
		if($(this).is(":checked")){			
			$(checks).prop("checked","checked");
		}else{
			$(checks).removeAttr("checked");
		}		
	});
	$(trs).on('click',function(){
		var c=$(this).find("input[type=checkbox]");
		if($(c).is(":checked")){
			$(c).removeAttr("checked");
		}else{
			$(c).prop("checked","checked");
		}		
	});
	//发送给会员
	$("#sendCard").on('click', function () {
		var checks=$(".Joel-check:checked");
		if(checks.length==0){
			$.Joel.alert('danger','请选择要发送的卡券！');
			return false;
		}
		if(checks.length>1){
			$.Joel.alert('danger','单次仅能发送一张卡券！');
			return false;
		}
		var cardid=checks.val();
		var cardstatus=$('#status'+cardid).text();
		if(cardstatus!='生成'){
			$.Joel.alert('danger','此卡券不能发放！');
			return false;
		}
		if($('#type'+cardid).text()=='充值卡'){
			$.Joel.alert('danger','充值卡暂不支持线上发放！');
			return false;
		}
		var carddetail=$('#money'+cardid).text()+"元"+$('#type'+cardid).text()+"　发送给：";
		
		
        bootbox.prompt(carddetail, function (result) {
            if (result != null) {
                var data={'cardid':cardid,'vipid':result};
                var tourl="{:U('Cms/vip/sendCard')}";
            	$.Joel.ajax('post',tourl,data,function(){$('#refresh-toggler').trigger('click');});
            }
        });
        
    });
	//全删
	$('#Joel-delall').on('click',function(){
		var checks=$(".Joel-check:checked");
		var chk='';
		$(checks).each(function(){
			chk+=$(this).val()+',';
		});
		if(!chk){
			$.Joel.alert('danger','请选择要删除的项目！');
			return false;
		}
		var toajax="{:U('Cms/Vip/cardDel')}"+"/id/"+chk;
		var funok=function(){
			var callok=function(){
				//成功删除后刷新
				$('#refresh-toggler').trigger('click');
				return false;
			};
			var callerr=function(){
				//拦截错误
				return false;
			};
			$.Joel.ajax('post',toajax,'nodata',callok,callerr);
		}						
		$.Joel.confirm("确认要删除吗？",funok);
	});
	
	$('#exportCard').on('click',function(){
		var checks=$(".Joel-check:checked");
		var chk='';
		$(checks).each(function(){
			chk+=$(this).val()+',';
		});
		window.open("{:U('Cms/Vip/cardExport')}/type/{$type}/id/"+chk);
	})
</script>
<!--/全选特效封装-->